<?php

         //查询子级函数封装
         function getcate($pid=0,$cate=array()){
          $sql = "SELECT * FROM  `cate` where pid = $pid ";
          $res1 = mysqli_query($GLOBALS['link'],$sql);
          while ($data=mysqli_fetch_assoc($res1)) {
          //将顶级存储到分类数组中
          $cate[] = $data;
          $cate = getcate($data['id'],$cate);
          }
          return $cate;
          }

          //编辑分类函数封装
          function getcateedit( $data,$cate=array()){
            $pid=$data['pid'];
          $sql = "select * from `cate` where `pid` = $pid";
          $result1 = mysqli_query($GLOBALS['link'],$sql);
          while($arr=mysqli_fetch_assoc($result1)){
                $cate[$data['id']][]=$arr;
          }

          if($pid!=0){
          $sql = "select * from `cate` where `id` = $pid";
          $result2 = mysqli_query($GLOBALS['link'],$sql);
          $date=mysqli_fetch_assoc($result2);
          $cate = getcateedit($date,$cate);
          }
          return $cate;
          $cate=array_reverse($cate,true);
          }




 ?>
